//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using Tathata.Common.Caching;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.Globalization;
using Tathata.Common.DAL;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.EntityCollections;
using Tathata.Common.DAL.Managers;

namespace Tathata.Common.BLL.Managers
{
    /// <summary>
    /// Product review manager
    /// </summary>
    public class ProductReviewManager
    {
        #region Methods
        /// <summary>
        /// Gets a product review
        /// </summary>
        /// <param name="ProductReviewID">Product review identifier</param>
        /// <returns>Product review</returns>
        public static ProductReview GetByProductReviewID(int ProductReviewID)
        {
            return ProductReviewDBManager.GetByProductReviewID(ProductReviewID);
        }

        /// <summary>
        /// Gets a product review collection by product identifier
        /// </summary>
        /// <param name="ProductID">Product identifier</param>
        /// <returns>Product review collection</returns>
        public static ProductReviewCollection GetByProductID(int ProductID)
        {
            bool showHidden = NopContext.Current.IsAdmin;
            return ProductReviewDBManager.GetByProductID(ProductID, showHidden);
        }

        /// <summary>
        /// Deletes a product review
        /// </summary>
        /// <param name="ProductReviewID">Product review identifier</param>
        public static void DeleteProductReview(int ProductReviewID)
        {
            ProductReviewDBManager.DeleteProductReview(ProductReviewID);
        }

        /// <summary>
        /// Gets all product reviews
        /// </summary>
        /// <returns>Product review collection</returns>
        public static ProductReviewCollection GetAllProductReviews()
        {
            bool showHidden = NopContext.Current.IsAdmin;
            return ProductReviewDBManager.GetAllProductReviews(showHidden);
        }

        /// <summary>
        /// Inserts a product review
        /// </summary>
        /// <param name="ProductID">The product identifier</param>
        /// <param name="CustomerID">The customer identifier</param>
        /// <param name="Title">The review title</param>
        /// <param name="ReviewText">The review text</param>
        /// <param name="Rating">The review rating</param>
        /// <param name="HelpfulYesTotal">Review helpful votes total</param>
        /// <param name="HelpfulNoTotal">Review not helpful votes total</param>
        /// <param name="IsApproved">A value indicating whether the product review is approved</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <returns>Product review</returns>
        public static ProductReview InsertProductReview(int ProductID, int CustomerID,
            string Title,string ReviewText, int Rating, int HelpfulYesTotal, 
            int HelpfulNoTotal, bool IsApproved, DateTime CreatedOn)
        {
            if (Rating < 1)
                Rating = 1;
            if (Rating > 5)
                Rating = 5;
            return ProductReviewDBManager.InsertProductReview(ProductID, CustomerID, 
                Title, ReviewText, Rating, HelpfulYesTotal, HelpfulNoTotal,
                IsApproved, CreatedOn);
        }

        /// <summary>
        /// Updates the product review
        /// </summary>
        /// <param name="ProductReviewID">The product review identifier</param>
        /// <param name="ProductID">The product identifier</param>
        /// <param name="CustomerID">The customer identifier</param>
        /// <param name="Title">The review title</param>
        /// <param name="ReviewText">The review text</param>
        /// <param name="Rating">The review rating</param>
        /// <param name="HelpfulYesTotal">Review helpful votes total</param>
        /// <param name="HelpfulNoTotal">Review not helpful votes total</param>
        /// <param name="IsApproved">A value indicating whether the product review is approved</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <returns>Product review</returns>
        public static ProductReview UpdateProductReview(int ProductReviewID,
            int ProductID, int CustomerID, string Title,
            string ReviewText, int Rating, int HelpfulYesTotal,
            int HelpfulNoTotal, bool IsApproved, DateTime CreatedOn)
        {
            return ProductReviewDBManager.UpdateProductReview(ProductReviewID,
                ProductID, CustomerID, Title, ReviewText, Rating,
                HelpfulYesTotal, HelpfulNoTotal, IsApproved, CreatedOn);
        }

        /// <summary>
        /// Sets a product rating helpfulness
        /// </summary>
        /// <param name="ProductReviewID">Product review identifer</param>
        /// <param name="WasHelpful">A value indicating whether the product review was helpful or not </param>
        public static void SetProductRatingHelpfulness(int ProductReviewID, bool WasHelpful)
        {
            if (NopContext.Current.User == null)
                return;

            ProductReviewDBManager.SetProductRatingHelpfulness(ProductReviewID,
                NopContext.Current.User.CustomerID,WasHelpful);
        }

        #endregion
    }
}
